babl_fish_reference(), create_name(): add conditional fastpath.
authorRoman Lebedev <lebedev.ri@gmail.com>
Fri, 19 Aug 2016 12:23:02 +0000 (15:23 +0300)
committerØyvind Kolås <pippin@gimp.org>
Sat, 20 Aug 2016 17:26:02 +0000 (19:26 +0200)
Using __thread keyword.
Although, it is probably not universally avaliable, so this
is just conditional fastpath, if it is detected as unsupported
at compile time, the dumb implementation using malloc() is used.

babl/babl-fish-reference.c
configure.ac

index fe75a71a924bbd559f0f7935d004d694dd7da1f1..7570e6a1e8ce66ce3ba066ebe28f8b74cefbdda7 100644 (file)
@@ -43,6 +43,28 @@ create_name_internal (char *buf,
                    source, destination);
 }
 
+#ifdef HAVE_TLS
+
+static __thread char buf[1024];
+
+static char *
+create_name (const Babl *source,
+             const Babl *destination,
+             int   is_reference)
+{
+  int size = 0;
+
+  size = create_name_internal (buf, sizeof(buf), source, destination, is_reference);
+
+  if (size < 0)
+    return NULL;
+
+  return buf;
+}
+
+
+#else
+
 static char *
 create_name (const Babl *source,
              const Babl *destination,
@@ -72,6 +94,7 @@ create_name (const Babl *source,
   return buf;
 }
 
+#endif
 
 Babl *
 babl_fish_reference (const Babl *source,
@@ -88,7 +111,9 @@ babl_fish_reference (const Babl *source,
       /* There is an instance already registered by the required name,
        * returning the preexistent one instead.
        */
+#ifndef HAVE_TLS
       free (name);
+#endif
       return babl;
     }
 
@@ -117,7 +142,9 @@ babl_fish_reference (const Babl *source,
    * name, inserting newly created class into database.
    */
   babl_db_insert (babl_fish_db (), babl);
+#ifndef HAVE_TLS
   free (name);
+#endif
   return babl;
 }
 
index 1bc301b6c082c90d0ca0210fb1cec98f18b1d33b..5bb74fc6973fc0a3e905b47bb996aa142d54c731 100644 (file)
@@ -283,6 +283,22 @@ AM_CONDITIONAL(OS_UNIX, test "$os_win32" != "yes")
 dnl ===========================================================================
 
 
+#################
+# Check for some not-so-common features
+#################
+
+# babl_fish_reference(), create_name() would like this
+AC_MSG_CHECKING([for __thread])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(, [static __thread char buf[1024];])],
+               [AC_DEFINE(HAVE_TLS, 1,
+                      Define to 1 if compiler supports __thread)
+                AC_MSG_RESULT([yes])],
+               [AC_MSG_RESULT([no])])
+
+
+dnl ===========================================================================
+
+
 ########################
 # Check for MMX assembly
 ########################